package com.lovo.dao;

import com.lovo.model.UserDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.persistence.LockModeType;
import java.util.List;

public interface UserDAO extends JpaRepository<UserDO,Integer> {
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    UserDO findByPhoneAndPwd(String phone,String pwd);

    @Query("from UserDO where phone=:phone")
    List findCondition(@Param("phone") String phone);

    @Modifying
    @Query(value="delete from user_info where phone=?1",nativeQuery=true)
    void deleteByPhone(String phone);

}
